package com.bootx.config;

import com.bootx.entity.OpenAiConfig;
import com.bootx.service.OpenAiConfigService;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author black
 */
@Configuration
public class ChatClientConfig {

    @Resource
    private OpenAiConfigService openAiConfigService;

    @Bean
    public ChatClient chatClient1() {
        OpenAiConfig openAiConfig = new  OpenAiConfig();
        openAiConfig.setApiKey("abc");
        openAiConfig.setBaseUrl("aa");

        OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
                .openAiApi(OpenAiApi.builder()
                        .apiKey(openAiConfig.getApiKey())
                        .baseUrl(openAiConfig.getBaseUrl()).build()
                ).defaultOptions(OpenAiChatOptions.builder().model("gpt-4o-2024-11-20").build()).build();
        return ChatClient.builder(openAiChatModel).build();
    }

    @Bean
    public ChatClient chatClient2() {
        OpenAiConfig openAiConfig = new  OpenAiConfig();
        openAiConfig.setApiKey("abc");
        openAiConfig.setBaseUrl("aa");
        OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
                .openAiApi(OpenAiApi.builder()
                        .apiKey(openAiConfig.getApiKey())
                        .baseUrl(openAiConfig.getBaseUrl()).build()
                ).defaultOptions(OpenAiChatOptions.builder().model("gpt-4o").build()).build();
        return ChatClient.builder(openAiChatModel).build();
    }

    @Bean
    public ChatClient chatClient() {
        return chatClient1();
    }

}
